﻿using Demo.Net.IdentityServer.IdentityServer;
using IdentityServer4;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace Demo.Net.IdentityServer.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize(AuthenticationSchemes = IdentityServerConstants.LocalApi.AuthenticationScheme)]
    public class TestController : ControllerBase
    {


        [HttpGet]
        public async Task<IActionResult> Test()
        {
            return Ok();
        }


        /// <summary>
        /// 获取登录的用户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetLoginUserInfo()
        {

         
            var userId =   User.GetUserId();
            var userName = User.GetUserName();
            var realName = User.GetUserRealName();
            return Ok(new { userId,userName,realName});
        }
    }
}
